package com.zzh.partnersys.ai.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzh.partnersys.ai.entity.ChatMessageDO;
import com.zzh.partnersys.ai.mapper.ChatMessageMapper;
import com.zzh.partnersys.ai.service.IChatMessageService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zzh
 * @since 2025-05-07
 */
@Service
public class ChatMessageServiceImpl extends ServiceImpl<ChatMessageMapper, ChatMessageDO> implements IChatMessageService {

    @Override
    public List<ChatMessageDO> findChatMessageLatestN(String conversationId, int lastN) {
        // 只根据conversationId查询，不涉及messageType
        return this.lambdaQuery()
                .eq(ChatMessageDO::getConversationId, conversationId)
                .last("limit " + lastN)
                .list();
    }

    @Override
    public void deleteChatMessageByConversationId(String conversationId) {
        this.remove(lambdaQuery().eq(ChatMessageDO::getConversationId,conversationId));
    }
}
